﻿using System;
using System.Linq;
using System.Collections;

namespace Xpedite
{
  internal class Verify
  {
    public static void NotNull<T>(T value, String paramName)
      where T : class
    {
      if (value == null)
        throw new ArgumentNullException(paramName, "Value cannot be null.");
    }

    public static void NotNullOrEmpty<T>(T value, String paramName)
      where T : IEnumerable
    {
      if (value != null && value.GetEnumerator().MoveNext())
        return;

      throw new ArgumentException("Value cannot be a null or empty.", paramName);
    }

    public static void NotWhiteSpace(String value, String paramName)
    {
      if (String.IsNullOrEmpty((value ?? String.Empty).Trim()))
        throw new ArgumentException("Value cannot be a null, empty or whitespace only.", paramName);
    }

    public static void True(Boolean expr, String paramName, String message)
    {
      if (!expr)
        throw new ArgumentException(message, paramName);
    }

    public static void False(Boolean expr, String paramName, String message)
    {
      if (expr)
        throw new ArgumentException(message, paramName);
    }
  }
}
